package com.gcit.seniorWish.web.modular.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.gcit.seniorWish.web.common.constant.cache.Cache;
import com.gcit.seniorWish.web.common.constant.cache.CacheKey;
import com.gcit.seniorWish.web.common.constant.enums.SystemConfigurateEnum;
import com.gcit.seniorWish.web.common.persistence.model.SystemConfigurate;
import com.gcit.seniorWish.web.common.persistence.dao.SystemConfigurateMapper;
import com.gcit.seniorWish.web.modular.system.service.ISystemConfigurateService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统配置表 服务实现类
 * </p>
 *
 * @author gaozhichang
 * @since 2018-03-27
 */
@Service
public class SystemConfigurateServiceImpl extends ServiceImpl<SystemConfigurateMapper, SystemConfigurate> implements ISystemConfigurateService {

	/**
	* 合并系统配置
	* @param sysConfig
	* @author gaozhichang
	* @date 2018-04-03 上午 11:29
	*/
	@Override
	@CacheEvict(value = Cache.CONSTANT, key = "'" + CacheKey.SYS_CONFIG + "'+#sysConfig.configurateKey")
	public void mergeSystemConfig(SystemConfigurate sysConfig){
		if (!StrUtil.isBlank(sysConfig.getId())) {
			this.updateById(sysConfig);
		}else{
			sysConfig.setConfigurateKey(SystemConfigurateEnum.SENIOR_WISH_END_DATE.getMessage());
			this.insert(sysConfig);
		}
	}
}
